// components/search/search.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    database:String
  },

  /**
   * 组件的初始数据
   */
  data: {
    input_value: '',
    flag:true
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //取消
    cancelTap: function () {
      this.triggerEvent("flagChange", true)
      this.setData({
        flag:true,
        input_value: '' //value值,
      })
    },
    //监听聚焦
    focusTap: function () {
      this.setData({
        flag:false
      })
      this.triggerEvent("flagChange", false)
    },
    //数据输入监听
    inputValue: function (event) {
      if (event.detail.value == '') {
        this.setData({
          flag: true
        })
        this.triggerEvent("flagChange", true)
      }
    },
    //数据查询
    searchTap: function (event) {
      const key = event.detail.value
      const that = this
      wx.cloud.callFunction({
        name: 'search',
        data: {
          keywords: key,
          database:that.data.database
        },
        success: res => {
          that.triggerEvent("detailList", res.result.data)
        },
        fail: res => {
          console.log('失败', res)
        }
      })

    },
  }
})
